﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp
{
   public class EnumExample
    {
        public static void ShowEnum()
        {
            // 使用键值对存储 SomeRootVegetables, Seasons
            Dictionary<SomeRootVegetables, Seasons> AvaiableIn = new Dictionary<SomeRootVegetables, Seasons>();
            AvaiableIn[SomeRootVegetables.HorseRadish] = Seasons.All;
            AvaiableIn[SomeRootVegetables.Radish]=Seasons.Spring;
            AvaiableIn[SomeRootVegetables.Turnip] = Seasons.Spring|Seasons.Autumn;
            
            Seasons[] theSeasons = new Seasons[] { Seasons.Summer, Seasons.Autumn, Seasons.Winter, Seasons.Spring };

            foreach (var season in theSeasons)
            {
                Console.WriteLine(string.Format("The following root vegetables are harvested in {0}:\n",season.ToString("G")));
                foreach (var item in AvaiableIn)
                {
                    // A bitwise comparison
                    if (((Seasons)item.Value & season) > 0)
                    {
                        Console.WriteLine(string.Format(" {0:G}\n",(SomeRootVegetables)item.Key));
                    }
                }
            }
        }
    }

    /// <summary>
    /// A triditional enumeration of some root vegetables
    /// </summary>
    public enum SomeRootVegetables
    {
        HorseRadish,
        Radish,
        Turnip
    }

    /// <summary>
    /// A bit field or flag enumeration of harvesting seasons.
    /// </summary>
    [Flags]
    public enum Seasons
    {
        None = 0,
        Summer= 1,
        Autumn= 2,
        Winter=4,
        Spring=8,
        All=Summer|Autumn|Winter|Spring
    }


}
